package team18.yuejian.Activity;

import android.content.Intent;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import team18.yuejian.Adapter.ShowPicAdapter;
import team18.yuejian.Model.ShowPicModel;
import team18.yuejian.R;
import team18.yuejian.RetrofitListener;
import team18.yuejian.bean.PicBean;

public class ShowPicActivity extends BaseActivity implements View.OnClickListener, RetrofitListener<List<PicBean>> {
    private RecyclerView recyclerView;
    private ShowPicAdapter adapter;
    private TextView title;
    private FloatingActionButton fab;
    private LinearLayout mine,showpic;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_pic);
        initView();
        initEvent();

    }

    public void initView(){
        recyclerView = findViewById(R.id.recycle_view);
        title = findViewById(R.id.showPicActivity_Title);
        fab = findViewById(R.id.fab);
        mine = findViewById(R.id.mine);
        showpic = findViewById(R.id.showpic);
    }

    public void initEvent(){
        fab.setOnClickListener(this);
        mine.setOnClickListener(this);
        ShowPicModel showPicModel = new ShowPicModel();
        showPicModel.GetShowPicList(this);
        title.setText("晒图列表");

        mine.setSelected(false);
        showpic.setSelected(true);
    }

    @Override
    public void onSuccess(List<PicBean> picBeans, int flag) {
        GridLayoutManager layoutManager = new GridLayoutManager(this,2);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new ShowPicAdapter(picBeans,1);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(ShowPicActivity.this,msg,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fab:
                Intent intent = new Intent(ShowPicActivity.this,PicAddActivity.class);
                startActivity(intent);
                break;
            case R.id.mine:
                Intent intent1 = new Intent(ShowPicActivity.this,MineActivity.class);
                startActivity(intent1);
                break;
        }
    }

    /*public void buttonBottom(){
        LayoutInflater factory = LayoutInflater.from(ShowPicActivity.this);
        View layout = factory.inflate(R.layout.bottom_menu, null);

        LinearLayout mine = layout.findViewById(R.id.mine);

        mine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ShowPicActivity.this,MineActivity.class);
                startActivity(intent);
            }
        });

    }*/
}
